package com.tjsinfo.tjsoa.mail.bo;

import java.util.Iterator;
import java.util.List;

import com.tjsinfo.tjsoa.mail.dao.ITjsAnnexDao;
import com.tjsinfo.tjsoa.mail.vo.TjsAnnex;
import com.tjsinfo.tjsoa.mail.vo.Tjsmail;

public class TjsmailAnnexBo implements ITjsmailAnnexBo{
	private final boolean STARTTRUE=true;
	private final boolean STARTFALSE=false;
	private ITjsAnnexDao  tjsAnnexDao;
	
	public ITjsAnnexDao getTjsAnnexDao() {
		return tjsAnnexDao;
	}

	public void setTjsAnnexDao(ITjsAnnexDao tjsAnnexDao) {
		this.tjsAnnexDao = tjsAnnexDao;
	}

	public boolean addTjsmailAnnex(String annexname, String annexaddress,
			String emailid, Integer user_id, Integer annexsize) {
		// TODO Auto-generated method stub
		try {
			TjsAnnex tjsAnnex = new TjsAnnex();//附件
			tjsAnnex.setAnnexName(annexname);
			tjsAnnex.setAnnexAddress(annexaddress);
			tjsAnnex.setAnnexSize(annexsize);
			Tjsmail tjsmail = new Tjsmail();
			tjsmail.setTjsmailId(emailid);
			tjsAnnex.setTjsmail(tjsmail);
			tjsAnnex.setUserid(user_id);
			tjsAnnexDao.save(tjsAnnex);
			return STARTTRUE;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return STARTFALSE;
	}

	public boolean deleteTjsmailAnnex(String mailid) {
		// TODO Auto-generated method stub
		try {
			List<TjsAnnex>  list = selectByMailid(mailid);//附件
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				TjsAnnex tjsAnnex = (TjsAnnex) iterator.next();
				tjsAnnexDao.delete(tjsAnnex);
			}
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return STARTFALSE;
		}
		return STARTTRUE;
	}

	public boolean deleteTjsmailAnnexById(String annexid) {
		// TODO Auto-generated method stub
		try {
			TjsAnnex tjsAnnex =	selectById(annexid);//附件
			tjsAnnexDao.delete(tjsAnnex);
			return STARTTRUE;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return STARTFALSE;
		}
	}

	public List<TjsAnnex> selectAnnexByUserid(Integer userid) {
		// TODO Auto-generated method stub
		return tjsAnnexDao.selectTjsAnnexByUserid(userid);
	}

	public TjsAnnex selectById(String id) {
		// TODO Auto-generated method stub
		return tjsAnnexDao.selectOneById(id);//附件
	}

	public List<TjsAnnex> selectByMailid(String mailid) {
		// TODO Auto-generated method stub
		return tjsAnnexDao.selectOneByMailId(mailid);//附件
	}

}
